﻿//Mirco Töpfer

using System;
using System.Collections.Generic;


namespace pheidippides.logging.Classes
{
    internal class LogDataManager
    {
        #region Singleton

        private static LogDataManager _staticLogDataManager;

        internal static LogDataManager GetInstance()
        {
            if (_staticLogDataManager == null)
                _staticLogDataManager = new LogDataManager();
            return _staticLogDataManager;
        }

        private LogDataManager()
        {
            _logEntryQueue = new Queue<LogEntry>();
            _last100LogEntrys = new Stack<LogEntry>(100);
        }

        #endregion

        #region Private Members

        private readonly Queue<LogEntry> _logEntryQueue;
        private readonly Stack<LogEntry> _last100LogEntrys;

        #endregion

        #region Internal Methods

        internal void EnQueueLogEntry(LogEntry entry)
        {
            lock (_logEntryQueue)
            {
                _logEntryQueue.Enqueue(entry);
            }
        }

        internal LogEntry DeQueueLogEntry()
        {
            lock (_logEntryQueue)
            {
                return _logEntryQueue.Dequeue();
            }
        }

        internal Int32 GetEntrysCount()
        {
            return _logEntryQueue.Count;
        }

        internal void WriteLoggingPuffer(LogEntry currentEntry)
        {
            _last100LogEntrys.Push(currentEntry);
        }

        internal List<LogEntry> GetLast100LogEntrys()
        {
            lock (_last100LogEntrys)
            {
                return new List<LogEntry>(_last100LogEntrys.ToArray());
            }
        }

        #endregion
    }
}